package com.ruoyi.develop.goodsPeople.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
        import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.ruoyi.develop.goodsPeople.mapper.GoodsPeopleMapper;
import com.ruoyi.develop.goodsPeople.domain.GoodsPeople;
import com.ruoyi.develop.goodsPeople.service.IGoodsPeopleService;

/**
 * 送货人Service业务层处理
 * @author qh
 * @date 2024-09-06
 */
@Service
public class GoodsPeopleServiceImpl implements IGoodsPeopleService {
    @Resource
    private GoodsPeopleMapper goodsPeopleMapper;

    /**
     * 查询送货人
     * @param id 送货人主键
     * @return 送货人
     */
    @Override
    public GoodsPeople selectById(String id) {
        return goodsPeopleMapper.selectById(id);
    }

    /**
     * 查询送货人列表
     * @param entity 送货人
     * @return 送货人
     */
    @Override
    public List<GoodsPeople> selectList(GoodsPeople entity) {
        return goodsPeopleMapper.selectList(entity);
    }

    /**
     * 新增送货人
     * @param entity 送货人
     * @return 结果
     */
    @Override
    public int insert(GoodsPeople entity) {
        if(StringUtils.isBlank(entity.getId())){
            entity.setId(IdUtils.fastSimpleUUID());
        }
                entity.setCreateBy(SecurityUtils.getUsername());
                entity.setCreateTime(DateUtils.getNowDate());
            return goodsPeopleMapper.insert(entity);
    }

    /**
     * 修改送货人
     * @param entity 送货人
     * @return 结果
     */
    @Override
    public int update(GoodsPeople entity) {
                entity.setUpdateBy(SecurityUtils.getUsername());
                entity.setUpdateTime(DateUtils.getNowDate());
        return goodsPeopleMapper.update(entity);
    }

    /**
     * 批量删除送货人
     * @param ids 需要删除的送货人主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String[] ids) {
        return goodsPeopleMapper.deleteByIds(ids);
    }

    /**
     * 删除送货人信息
     * @param id 送货人主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return goodsPeopleMapper.deleteById(id);
    }


    @Override
    public List<SysDictData> selectAllPeople(GoodsPeople param) {
        List<SysDictData> dictDatas = new ArrayList<>();
        List<GoodsPeople> lists = selectList(param);
        lists.stream().forEach(entity -> {
            SysDictData dict = new SysDictData();
            dict.setDictLabel(entity.getSonghuoren());
            dict.setDictValue(entity.getId());
            dict.setLabel(entity.getSongkaihuhang());
            dict.setValue(entity.getSongzhanghao());
            dictDatas.add(dict);
        });
        return dictDatas;
    }

}
